﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Evolution
{
    /// <summary>
    /// класс Хищников (базовый обычная клетка)
    /// </summary>
    class Predator : Cel 
    {
        /// <summary>
        /// Переменная для 
        /// </summary>
        public bool isAttack { get; set; }

        public Predator(int Row, int Column)
        {
            column = Column;
            row = Row;
            Symbol = '*';
            isAttack = false;
        }     

        public override Cel CopyTo()
        {
            Predator tmp = new Predator(row, column);
            tmp.Level = Level;
            tmp.isAttack = isAttack;
            return tmp;
        }

        public override void OneStep(Evol evol, ref Cel curCel)
        {
            int maxRowIndex, minRowIndex, maxColumnIndex, minColumnIndex;
            maxRowIndex = Math.Min(evol.Size - 1, row + 1);
            minRowIndex = Math.Max(0, row - 1);
            maxColumnIndex = Math.Min(evol.Size - 1, column + 1);
            minColumnIndex = Math.Max(0, column - 1);

            int countCel = (maxRowIndex - minRowIndex + 1) * (maxColumnIndex - minColumnIndex + 1) - 1;
            for (int i = minRowIndex; i <= maxRowIndex; i++)
                for (int j = minColumnIndex; j <= maxColumnIndex; j++)
                {
                    if (i == row && j == column) continue;

                    if (evol[i, j] is Predator) countCel--;
                    else if (evol[i, j] is Vegetarian) countCel--;
                }

            if (countCel == 0)
                curCel = new Cel(row, column);
            else 
                ((Predator)curCel).IncLevel();
        }
        public override void Show()
        {
            ConsoleColor OldColor = Console.ForegroundColor;
            Console.ForegroundColor = ConsoleColor.Red;
            base.Show();
            Console.ForegroundColor = OldColor;
        }
    }
}
